package core.query;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class QuickFilter implements Serializable {

	private static final long serialVersionUID = 7677349099146496516L;

	private List<String> keywordList = new ArrayList<String>();

	private Object filterValue;

	private String value;

	private String operator = "like";

	private String prefix = "%";
	private String subfix = "%";

	public QuickFilter bindKeyword(String keyword) {
		keywordList.add(keyword);
		return this;
	}

	public List<String> getKeywordList() {
		return keywordList;
	}

	public Object getFilterValue() {
		return filterValue;
	}

	public String getOperator() {
		return operator;
	}

	public void setFilterValue(Object filterValue) {
		this.filterValue = filterValue;
		this.value = this.prefix + transfer(filterValue.toString())
				+ this.subfix;
	}

	public String getValue() {
		return this.value;
	}

	public static String transfer(String keyword) {
		if (keyword.contains("%") || keyword.contains("_")) {
			keyword = keyword.replaceAll("\\\\", "\\\\\\\\")
					.replaceAll("\\%", "\\\\%").replaceAll("\\_", "\\\\_");
		}
		return keyword;
	}

}
